package com.cskaoyan.order.biz.handler;

import com.cskaoyan.mall.dto.ClearCartItemRequest;
import com.cskaoyan.mall.dto.ClearCartItemServiceResponse;
import com.cskaoyan.order.biz.context.CreateOrderContext;
import com.cskaoyan.order.biz.context.TransHandlerContext;
import com.cskaoyan.order.remote.ProductApiClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ClearCartItemHandler extends AbstractTransHandler {

    @Autowired
    private ProductApiClient productApiClient;


    //是否采用异步方式执行
    @Override
    public boolean isAsync() {
        return false;
    }

    @Override
    public boolean handle(TransHandlerContext context) {
        CreateOrderContext createOrderContext= (CreateOrderContext) context;
        if (createOrderContext.getCartProductDtoList().size()==1) {
            productApiClient.deleleCart(createOrderContext.getUserId(),createOrderContext.getCartProductDtoList().get(0).getProductId());
        }
        else{
            productApiClient.deleteCheckCart(createOrderContext.getUserId());
        }
        return true;
    }
}
